package com.fzt.framework.service;

import com.fzt.common.constant.RedisKeys;
import com.fzt.framework.user.UserDetail;
import com.fzt.framework.utils.RedisUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 *
 * </p>
 *
 * @author 非洲铜
 * @since 2022-12-08
 */
@AllArgsConstructor
@Service
public class TokenService {

    private final RedisUtils redisUtils;

    public void saveUser(String accessToken, Object user) {
        String key = RedisKeys.getAccessTokenKey(accessToken);
        redisUtils.set(key, user);
    }


    public UserDetail getUser(String accessToken) {
        String key = RedisKeys.getAccessTokenKey(accessToken);
        Object o   = redisUtils.get(key);
        return (UserDetail) o;
    }


    public void deleteUser(String accessToken) {
        String key = RedisKeys.getAccessTokenKey(accessToken);
        redisUtils.delete(key);
    }
}
